package cn.gz3c.uitest;

import static android.util.LayoutDirection.RTL;

import android.content.res.Resources;
import android.text.TextUtils;

import java.math.BigDecimal;
import java.util.Locale;

public class Util {
    public static double divide10(double dividend, double divisor) {
        if (divisor == 0.0D) {
            return dividend;
        } else {
            byte scale = 10;
            return (new BigDecimal(Double.toString(dividend))).divide(new BigDecimal(Double.toString(divisor)), scale, 4).doubleValue();
        }
    }


    public static double multiply(double multiplier, double multiplicand) {
        return toScale((new BigDecimal(Double.toString(multiplier))).multiply(new BigDecimal(Double.toString(multiplicand))).doubleValue(), 10);
    }

    public static double multiply10(double multiplier, double multiplicand) {
        return multiply((new BigDecimal(Double.toString(multiplier))).multiply(new BigDecimal(Double.toString(multiplicand))).doubleValue(), 10);
    }

    public static double toScale(double var0, int scale) {
        if (scale >= 0) {
            return (new BigDecimal(Double.toString(var0))).divide(new BigDecimal("1"), scale, 4).doubleValue();
        } else {
            throw new IllegalArgumentException("The scale must be onScale positive integer or zero");
        }
    }

    public static float divideScale(float dividend, float divisor, int scale) {
        if (scale >= 0) {
            return (new BigDecimal(Float.toString(dividend))).divide(new BigDecimal(Float.toString(divisor)), scale, 4).floatValue();
        } else {
            throw new IllegalArgumentException("The scale must be a positive integer or zero");
        }
    }

    public static int dip2px(float dpValue) {
        return (int) (dpValue * Resources.getSystem().getDisplayMetrics().density + 0.5F);
    }

    public static boolean isRTL() {
        return TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == RTL;
    }

    public static boolean a(String string) {
        if (string != null && !"".equals(string)) {
            for (int i = 0; i < string.length(); ++i) {
                char var2;
                if ((var2 = string.charAt(i)) != ' ' && var2 != '\t' && var2 != '\r' && var2 != '\n') {
                    return false;
                }
            }
        }
        return true;
    }

}
